<?php
class Slider extends Doctrine_Record {
    public function setTableDefinition() {
        $this->setTableName('slider');
        $this->hasColumn('titulo_es', 'string', 255);
        $this->hasColumn('titulo_en', 'string', 255);
        $this->hasColumn('titulo_pt', 'string', 255);
        $this->hasColumn('leyenda_es', 'string', 10000);
        $this->hasColumn('leyenda_en', 'string', 10000);
        $this->hasColumn('leyenda_pt', 'string', 10000);
        $this->hasColumn('id_categoria', 'integer');
    }
    
    public function setUp(){
        $this->hasOne('Categoria as categoria',array(
            'local'=>'id_categoria',
            'foreign'=>'id'
        ));
        $this->hasMany('Imagen as imagenes', array(
            'local' => 'id',
            'foreign' => 'id_slider'
        ));
    }
    
    //GETTERS Y SETTERS
   public function getTitulo($language='es') {
        return utf8_decode($this->_get('titulo_'.$language));
    }
    public function setTitulo ($q, $language='es') {
        $this->_set('titulo_'.$language, utf8_encode($q));
    }
    
    public function getLeyenda($language='es') {
        return utf8_decode($this->_get('leyenda_'.$language));
    }
    public function setLeyenda ($q, $language='es') {
        $this->_set('leyenda_'.$language, utf8_encode($q));
    }
    
    public function getPortada () {
        $q = Doctrine_Query::create()
            ->select('i.*')
            ->from('Imagen i')
            ->innerJoin('i.slider s')
            ->where('s.id = '.$this->id)
            ->limit(1)
            ->offset(0)
            ->orderBy('i.orden');
        $resultado = $q->execute();
        return $resultado[0];
    }
    //FIN GETTERS Y SETTERS
    
    public function imagenes () {
        $q = Doctrine_Query::create()
            ->select('i.*')
            ->from('Imagen i')
            ->innerJoin('i.slider s')
            ->where('s.id = '.$this->id)
            ->orderBy('i.orden');
        return $q->execute();
    }
}
?>